<?php
// $Id$

/**
 * Controller_Online 控制器
 */
class Controller_Online extends Controller_Abstract
{

	function actionIndex()
	{
        // 为 $this->_view 指定的值将会传递数据到视图中
		# $this->_view['text'] = 'Hello!';
		if($this->_context->isPOST())
		{
			$title = $this->_context->title;
			$content = $this->_context->content;
			$type = $this->_context->type;
			$name = $this->_context->name;
			if($title)
			{
				$title = strip_tags($title);
			}else
			{
				return $this->_redirectMessage('填写错误', '您必须填写咨询标题', url('online/index'));
			}
			if($content)
			{
				$content = strip_tags($content);
			}else
			{
				return $this->_redirectMessage('填写错误', '您必须填写咨询内容', url('online/index'));
			}
			if($type)
			{
				$type = strip_tags($type);
			}else
			{
				return $this->_redirectMessage('填写错误', '您必须填写咨询类型', url('online/index'));
			}
			if($name)
			{
				$name = strip_tags($name);
			}else
			{
				return $this->_redirectMessage('填写错误', '您必须填写您的名字', url('online/index'));
			}
			try {
				$obj = new Online();
				$obj->title = $title;
				$obj->content = $content;
				$obj->type = $type;
				$obj->name = $name;
				$obj->save(0,'create');
			} catch (Exception $e) {
			}
			
		}
		
		$pagesize = 10;
		$page = intval($this->_context->pageNum)?intval($this->_context->pageNum):1;
		$pagination = NULL;
		$param_array = $this->get_param();
		if($this->_context->id)
		{
			$param = 'id = '.intval($this->_context->id);
		}else{
			$param = '';
		}
		$data = Online::find($param)->limitPage($page,$pagesize)->fetchPagination($pagination)->order('id desc')->get();
		
		$this->_view['param'] 		= $param_array;
		$this->_view['pagination']	= $pagination;
		$this->_view['online']      	= $data;
		
	}
}


